package com.lucyyun.lcprovider;

import com.lucyyun.lcrpccore.RpcApplication;
import com.lucyyun.lcrpccore.config.RegistryConfig;
import com.lucyyun.lcrpccore.config.RpcConfig;
import com.lucyyun.lcrpccore.constant.RpcConstant;
import com.lucyyun.lcrpccore.model.ServiceMetaInfo;
import com.lucyyun.lcrpccore.registry.Registry;
import com.lucyyun.lcrpccore.registry.RegistryFactory;
import com.lucyyun.lcrpceasy.registry.LocalRegistry;
import com.lucyyun.lcrpceasy.server.HttpServer;
import com.lucyyun.lcrpceasy.server.VertxHttpServer;
import com.lucyyun.lucycommon.service.Userservice;

/**
 * Description
 *
 * @author: lucyYun
 * @date: 2024/6/23 16:52
 */
public class EasyProviderExample {
    public static void main(String[] args) {
//        LocalRegistry.registry(Userservice.class.getName(), UseServiceImpl.class);
//        HttpServer httpServer = new VertxHttpServer();
//        httpServer.doStart(8082);

        RpcApplication.init();
//        LocalRegistry.registry(Userservice.class.getName(), UseServiceImpl.class);

        String serviceName = Userservice.class.getName();
        LocalRegistry.registry(serviceName, UseServiceImpl.class);

        // 从注册中心获取服务提供者请求地址
        RpcConfig rpcConfig = RpcApplication.getRpcConfig();
        RegistryConfig registryConfig = rpcConfig.getRegistryConfig();
        Registry registry = RegistryFactory.getInstance(registryConfig.getRegistry());
        ServiceMetaInfo serviceMetaInfo = new ServiceMetaInfo();
        serviceMetaInfo.setServiceName(serviceName);
        serviceMetaInfo.setServiceHost(rpcConfig.getServerHost());
        serviceMetaInfo.setServicePort(rpcConfig.getServerPort());
        serviceMetaInfo.setServiceAddress(rpcConfig.getServerHost()+":"+rpcConfig.getServerPort());
        
        try {
            registry.register(serviceMetaInfo);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }


        HttpServer httpServer = new VertxHttpServer();
        httpServer.doStart(RpcApplication.getRpcConfig().getServerPort());
        
    }
}
